<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script type="text/javascript">

	$(function(){
		initNeedKcsj();
	});

	//初始化是否需要勘察时间
	function initNeedKcsj(){
		var needKcsj = '${needKcsj}';
		var needKcsjObj = document.getElementById("needKcsj");
		if(needKcsj == 1){
			needKcsjObj.checked = "checked";
			document.getElementById("kcsj").disabled = false;
		}else{
			needKcsjObj.checked = "";
			document.getElementById("kcsj").disabled = true;
			
		}
	}

	//验证是否需要勘察时间
	function checkNeedKcsj(obj){
		var needKcsjObj = document.getElementById("needKcsj");
		if(obj.checked){
			needKcsjObj.value = 1;
			document.getElementById("kcsj").disabled = false;
		}else{
			needKcsjObj.value = 2;
			document.getElementById("kcsj").value = "";
			document.getElementById("kcsj").disabled = true;
		}
	}
	//上传图片窗口
	var showUploadWindow=new Ext.Window({
        closeAction:'hide',
        title:'选择图片',
        width:430,
        height:100,
        layout:'form',
        buttonAlign:'center',
        labelAlign:'right',
        items:[{
            xtype:'textfield',
            fileUpload: true, 
            fieldLabel:'请选择图片',
            name:'attach',
            inputType:'file'
        }],
        buttons:[{text:'保存',handler:uploadFj},{text:'取消',handler:function(){
            showUploadWindow.hide();
        }}]
    });
    
    function openShowUploadWindow(){
    	showUploadWindow.show();
    }
    function uploadFj(){
    	var attache = dwr.util.getValue('attach');
	    if (attache.value == '') { Ext.Msg.alert("提示!","请选择附件!");return; }
	    var dotIndex = attache.value.lastIndexOf(".");
	    if (dotIndex < 0) dotIndex = attache.value.length;
	    var attacheName = attache.value.substring(attache.value.lastIndexOf("\\") + 1, dotIndex);
	    var attacheType = attache.value.substring(dotIndex + 1);
	    var ajid='${id}';
    	if(ajid==null){Ext.Msg.alert("提示!","请先保存案件!");return;}
    	var templateCode = WF_CONFIG.templateCode;
    	YwUtil.wait('图片上传中，请稍后！');
    	FileUploadCntl.uploadXckcImage(ajid,templateCode,attacheName,attacheType,attache, function (result){
	    	var array = eval('(' + result + ')');
	    	if(array.success == true){
				alert("添加成功!");
				Ext.Msg.hide();
				showUploadWindow.hide();
				var imgId = array.result.id;
			    var imgTitle = attacheName+'.'+attacheType;
			    var fjUrl = '${ctx}'+array.result.filepath;//
			    var fjUrl2 = "'"+fjUrl+"'";
			    
			    var html = '<span style="height:23px"><a href="javascript:openFj('+fjUrl2+');" title="'+imgTitle+'"><img src="${ctx}/resources/images/fileType/'+attacheType+
		    		'.gif" onerror="nofound();" border="0" class="img_16x16"/>'+imgTitle+'</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:deleteFj('+imgId+');"><font style="font-size:12px">删除</font></a></span>';
	    		var uploadimageInnerHtml = document.getElementById("imageDiv").innerHTML;
			    if(uploadimageInnerHtml != ""){
			    	document.getElementById("imageDiv").innerHTML = document.getElementById("imageDiv").innerHTML + "<br/>" + html;
			    }else{
			    	document.getElementById("imageDiv").innerHTML = "<br/>" + html;
			    }
	    	}else{
	    		alert("添加失败!");
	    		Ext.Msg.hide();
	    	}
			//window.location.reload();
		});
    }
    
    //删除附件
	function deleteFj(imgId){
		var r=confirm("确定要删除吗？");
  		if (r==true){
  			Ext.Ajax.request({
		      url:'${ctx}/yw-yn-jzfqwczz-xckctp!deleteImageById.action',
		      params:{
		        'imgId': imgId
		      },
		      success:function(response){
			  	var returnStr = response.responseText;
				var obj = eval('(' + returnStr + ')');
				var su = obj.success;
				if(obj.success){
					alert("删除成功！");
					//加载现场勘察表图片
	    			getImages();
				}else{
					alert("删除失败！");
				}
		      },
		      failure:function(){
				
			  },
		      scope:this
		   });
  		}			
	}
    
    function openFj(url) {
  		window.open(url);
	}
	function nofound(){
		var img=event.srcElement; 
		img.src="${ctx}/resources/images/fileType/default.gif"; 
		img.onerror=null;//控制不要一直跳动 
	}
	
</script>
<style type="text/css">
.inputButton{margin-top:10px;margin-left:5px;}
.imageDiv{margin-left:5px;padding:2;}
</style>

<table width="700" border="0" cellspacing="2" cellpadding="2">
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="2" cellpadding="2">
          		<tr>
          			<td height="55" bordercolor="#000000" align="center" style="font-family:宋体,华文仿宋;font-size:22px;">
            			<br/><b>现场勘查</b><br/><br/>
          			</td>
          		</tr>
        	</table>
        </td>
	</tr>
      
	<tr>
		<td>
			<table width="100%" border="1" cellspacing="0" cellpadding="2" class="tpl_list_ui">
				<tr>
                  	<td width="10%" height="0"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
                </tr>
                <tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">地貌有无改变</td>
					<td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	&nbsp;&nbsp;&nbsp;&nbsp;
					 	<input type="checkbox" name="dmywgb" value="1" ${fn:indexOf(dmywgb, '1') ge 0 ? 'checked' : ''}/>回填&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	                    <input type="checkbox" name="dmywgb" value="2" ${fn:indexOf(dmywgb, '2') ge 0 ? 'checked' : ''}/>劈山&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	                    <input type="checkbox" name="dmywgb" value="3" ${fn:indexOf(dmywgb, '3') ge 0 ? 'checked' : ''}/>拆屋&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	                    <input type="checkbox" name="dmywgb" value="4" ${fn:indexOf(dmywgb, '4') ge 0 ? 'checked' : ''}/>下挖&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</td>
                </tr>
                <tr>                	
	                <td bordercolor="#000000" colspan="3" height="25" align="center"> 红线图上原地标高</td>
	                <td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
	                   	<input class="text" name="hxtsydbg" value="${hxtsydbg}" style="width:100%" />
	                </td>
                </tr>
                <tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">施工现场相当于绝对标高</td>
					<td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	<input class="text" name="sgxcxdyjdbg" value="${sgxcxdyjdbg}" style="width:100%" />
					</td>
                </tr>
                <tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">正负零零</td>
					<td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	<input class="text" name="zfll" value="${zfll}" style="width:100%" />
					</td>
                </tr>
                <tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">施工面积</td>
					<td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	<input class="text" name="sgmj" value="${sgmj}" style="width:100%" />
					</td>
                </tr>
                <tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">土质情况</td>
					<td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	<textarea rows="5" style="width:100%" name="tzqk">${tzqk}</textarea>
					</td>
                </tr>
                <tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">
						<!-- 为2，则不需要勘察时间 -->
						<input type="checkbox" value="${needKcsj}" ${fn:indexOf(needKcsj, '1') ge 0 ? 'checked' : ''} onclick="checkNeedKcsj(this)"/>
						勘察时间
					</td>
					<td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	<input id="kcsj" name="kcsj" style="width:50%" value="<s:date name='kcsj' format="yyyy年MM月dd日"/>" onclick="WdatePicker({skin:'ext', dateFmt:'yyyy年MM月dd日'});" type="text" class="textdocWdate" readonly /><font color="red">不需要勘察时，请在备注说明</font>
					</td>
                </tr>
                <tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">勘察人员</td>
					<td colspan="7" bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	<input class="text" id="kcry" name="kcry" value="${kcry}" style="width:70%" />
					 	<input type="button" value="随行人员" onclick="selectUser('kcry')"/>
					</td>
				</tr>
				<tr>
					<td bordercolor="#000000" colspan="3" height="25" align="center">图片</td>
					<td colspan="7" valign="top" height="150"  bordercolor="#000000" style="padding: 1px 1px 1px 1px;">
					 	<input type="button" class="inputButton" value="添加图片" onclick="openShowUploadWindow()"/>
					 	<div class="imageDiv" id="imageDiv"></div>
					 	<br/>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
	<tr>
        <td>&nbsp;</td>
	</tr>
</table>